package com.cjy.menu.action;

import com.base.common.action.AbstractBaseAction;
import com.base.common.bean.ActionResult;
import com.cjy.common.bean.OpAttributes;
import com.cjy.menu.service.MenuService;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import javax.annotation.Resource;

import static com.base.GlobaConstants.*;
import static com.base.GlobaConstants.CONTENT_TYPE;
import static com.base.GlobaConstants.CONTENT_TYPE_JSON;

/**
 * Created by Kevin on 2017-9-12.
 */

@Action("menuAction")
@Results({ @Result(name = ASYNCHRONOUS, type = JSON, params = { ROOT,
        ACTION_RESULT_DATA, CONTENT_TYPE, CONTENT_TYPE_JSON }) })
public class MenuAction extends AbstractBaseAction {

    @Resource
    private MenuService menuService;

    private int bid;

    private int compoundsId;

    public int getBid() {
        return bid;
    }

    public void setBid(int bid) {
        this.bid = bid;
    }

    public int getCompoundsId() {
        return compoundsId;
    }

    public void setCompoundsId(int compoundsId) {
        this.compoundsId = compoundsId;
    }

    public String queryMenu() {
        try {
            actionResult = ActionResult.getActionResult(new OpAttributes<>().add("code", 1).add("result", menuService.queryMenu(bid, compoundsId)));
        } catch (Exception e) {
            e.printStackTrace();
            actionResult = ActionResult.getActionResult(new OpAttributes<>().add("code", 0));
        }
        return returnType();
    }

}
